{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f70291a0-1832-4372-a938-64ee8b2a187b",
   "metadata": {},
   "source": [
    "# 算法工程师如何优雅地使用ChatGPT?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c14fe389-d283-4848-a3a9-78699a05e986",
   "metadata": {},
   "source": [
    "torchkeras封装了 chatgpt的快捷魔法命令。\n",
    "\n",
    "可以在jupyter notebook中非常便捷地和chatgpt进行对话。\n",
    "\n",
    "并且可以设置对话的轮数。\n",
    "\n",
    "视频演示： https://www.bilibili.com/video/BV1Gs4y197hJ/\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "033d5a78-9c13-4a2a-b4e6-774ef25d86a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torchkeras.chat import ChatGPT\n",
    "\n",
    "key = 'xx-'\n",
    "#proxy = \"https://api.lixining.com/v1/chat/completions\" \n",
    "#proxy = \"https://chatai.1rmb.tk/api/v1/chat/completions\"\n",
    "proxy =  \"https://api.lixining.com/v1/chat/completions\"  \n",
    "chatgpt = ChatGPT(api_key=key,\n",
    "                  max_chat_rounds=3, #支持3轮连续对话\n",
    "                  #proxy = proxy #如果国内连接不上，可以使用网络代理\n",
    "                 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2e27a38-b490-4de6-beeb-397ec08af99b",
   "metadata": {},
   "outputs": [],
   "source": [
    "chatgpt('中国什么时候加入WTO的呢？') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf4f10df-8af0-49ee-b578-8469b650078e",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt \n",
    "印度呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd06be3c-8a3b-44b2-9013-b8dd60a947ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "俄罗斯呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a752e773-10b1-4b53-af62-992a82ade47c",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "韩国呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96e4b7c0-eae1-4e66-bb67-46aabcd54484",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "俄罗斯呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ceca958-2618-4dde-8cc9-05fc78819072",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "朝鲜呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "159432e8-eb21-4ea0-a810-87e0badb28af",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "古巴呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86542a0d-4387-4d18-8c5a-5286b0c82409",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%chatgpt\n",
    "三本三国演义可以合成一本九国演义吗？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03d41ab2-566d-4e8a-9f21-a490198de0ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "chatgpt.messages "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
